home *** CD-ROM | disk | FTP | other *** search
- ; kbdio.a - keyboard functions.
- ; (C) Copyright 1985 Cray Research Inc. - All Rights Reserved.
- ; G. R. Mansfield. 85/07/18.
- ; Ver 1.0-5821.
-
-
- include "include/ascii.ah"
- include "include/kbdio.ah"
- include "include/msdos.ah"
-
- ; ROM-BIOS interrupts.
-
- I_CTC equ 023h ; Control-C interrupt
- I_PRS equ 005h ; print screen interrupt
-
- I_KR equ 016h ; keyboard request interrupt
- KR_RC equ 0 ; read character
- KR_KS equ 1 ; keyboard status
-
-
- dseg
-
- ; Local data.
-
- ; KCT - Keyboard character conversion table.
-
- kct:
- db 0
- dw KBD_CBK
- db 59
- dw KBD_F1
- db 60
- dw KBD_F2
- db 61
- dw KBD_F3
- db 62
- dw KBD_F4
- db 63
- dw KBD_F5
- db 64
- dw KBD_F6
- db 65
- dw KBD_F7
- db 66
- dw KBD_F8
- db 67
- dw KBD_F9
- db 68
- dw KBD_F10
- db 71
- dw KBD_HM
- db 72
- dw KBD_UP
- db 73
- dw KBD_PU
- db 75
- dw KBD_LF
- db 77
- dw KBD_RT
- db 79
- dw KBD_ED
- db 80
- dw KBD_DN
- db 81
- dw KBD_PD
- db 82
- dw KBD_IN
- db 83
- dw KBD_DL
- db 114
- dw KBD_CPS
- db 115
- dw KBD_CLF
- db 116
- dw KBD_CRT
- db 117
- dw KBD_CED
- db 119
- dw KBD_CHM
- db 120
- dw KBD_A1
- db 121
- dw KBD_A2
- db 122
- dw KBD_A3
- db 123
- dw KBD_A4
- db 124
- dw KBD_A5
- db 125
- dw KBD_A6
- db 126
- dw KBD_A7
- db 127
- dw KBD_A8
- db 128
- dw KBD_A9
- db 129
- dw KBD_A0
- db 253
- dw KBD_CBK
- db 254
- dw KBD_PS
- kcta db 0
- dw -1 ; illegal character
-
- ccv dw 0,0 ; Control-C interrupt vector
- psv dw 0,0 ; PrtSc interrupt vector
-
-
- ; Public data.
-
- public kbd_kc_
-
- kbd_kc_ dw 0 ; keyboard character
-
-
- cseg
- ki dw 0 ; keyboard input (e.g. from an interrupt)
-
- ; Public functions.
-
- public kbd_bgn_
- public kbd_end_
- public kbd_getc_
- public kbd_csts_
-
-
- ; int kbd_getc() /* console input */
-
- kbd_getc_:
- gtc: cmp ki,0
- jnz gtc5 ; if keyboard input preset
- mov ah,KR_RC ; read keyboard character
- push bp
- int I_KR
- pop bp
- gtc1: mov kbd_kc_,ax
- cmp al,0
- jz gtc3 ; if extended character set
- mov ah,0
- cmp al,CV_CR ; convert CR to '\n'
- jnz gtc2
- mov al,CV_LF
- gtc2: ret
-
- gtc3: mov si,offset kct-2 ; look up character
- mov kcta,ah
- gtc4: inc si ; skip conversion
- inc si
- lodsb
- cmp al,ah
- jnz gtc4
- lodsw ; get conversion
- ret
-
- gtc5: xor ax,ax ; clear character and process
- xchg ax,ki
- jmp gtc1
-
-
- ; int kbd_csts() /* keyboard status, return character if any available,
- ; else return 0 */
-
- kbd_csts_:
- cmp ki,0
- jnz gtc ; if character preset
- mov ah,KR_KS
- push bp
- int I_KR
- pop bp
- jnz gtc ; keyboard input available
- xor ax,ax
- ret
-
-
- ; kbd_bgn(cf) /* begin interrupt processing */
- ; boolean cf;
-
- kbd_bgn_:
- mov bx,sp ; check Control-C flag
- mov ax,[bx+2]
- push es
- or ax,ax
- jnz bgn1 ; if set to allow interrupt to halt program
- mov ax,(FR_GIV*256) + I_CTC ; replace Control-C interrupt
- int I_FCN
- mov ccv,bx
- mov ccv+2,es
- mov dx,offset cci
- push ds
- push cs
- pop ds
- mov ax,(FR_SIV*256) + I_CTC
- int I_FCN
- pop ds
- bgn1: mov ax,(FR_GIV*256) + I_PRS ; replace print screen interrupt
- int I_FCN
- mov psv,bx
- mov psv+2,es
- mov dx,offset psi
- push ds
- push cs
- pop ds
- mov ax,(FR_SIV*256) + I_PRS
- int I_FCN
- pop ds
- pop es
- ret
-
-
- ; kbd_end() /* end keyboard processing */
-
- kbd_end_:
- mov ax,ccv ; check Control-C interrupt
- add ax,word ccv+2
- jz end1 ; if not set
- push ds ; restore Control-C interrupt
- lds dx,ccv
- mov ax,(FR_SIV*256) + I_CTC
- int I_FCN
- pop ds
- end1: push ds ; restore print screen interrupt
- lds dx,psv
- mov ax,(FR_SIV*256) + I_PRS
- int I_FCN
- pop ds
- ret
-
-
- ; CCI - Control-C interrupt processor.
-
- cci: mov word ki,CV_ETX ; set Control-C character
- iret
-
-
- ; PSI - PrtSc interrupt processor.
-
- psi: mov word ki,0FE00h ; set PrtSc character
- iret
-